package com.zr.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionSupport;
import com.zr.service.SerachUsersByInfoService;

import net.sf.json.JSONObject;

@Controller
public class SerachUsersByInfoAction extends ActionSupport implements ServletResponseAware,ServletRequestAware,SessionAware{
              
	private HttpServletResponse resp;
	 private  Map<String,Object> session; 
	 private HttpServletRequest req;	
	 @Override
		public void setSession(Map<String, Object> session) {
			this.session = session;
		}

		@Override
		public void setServletResponse(HttpServletResponse response) {
			this.resp = response;
		}
		
		@Override
		public void setServletRequest(HttpServletRequest request) {
			this.req = request;
		}
		
		@Resource
		private SerachUsersByInfoService serachUsersByInfoService;
		
		public void serachUsersByInfo(){
			resp.setCharacterEncoding("utf8");
			String searType = req.getParameter("searType");
			String sertInfo = req.getParameter("sertInfo");
			String pages = req.getParameter("page");
			String rowss = req.getParameter("rows");
			int page = Integer.parseInt(pages);
			int rows = Integer.parseInt(rowss);
			JSONObject j = serachUsersByInfoService.getUsersByInfo(page, rows, searType, sertInfo);
			try {
				PrintWriter pw = resp.getWriter();
					pw.write(j.toString());
					pw.flush();
					pw.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}
}
